! function() {
	function t(t, e) {
		return t.getAttribute(e)
	}

	function e(t, e, a) {
		window.attachEvent ? t.attachEvent("on" + e, a) : t.addEventListener(e, a, !1)
	}

	function a(t) {
		t = t || window.event;
		var e = t.target || t.srcElement,
			a = "A" === e.nodeName ? e : function() {
				for (var t = e; t.parentNode && (t = t.parentNode, "A" !== t.nodeName););
				return t
			}(),
			r = "AREA" === e.nodeName ? e : null;
		if (!("A" !== a.nodeName && !r || a.href && a.href.indexOf("javascript:") > -1)) {
			var n = r ? r : a,
				p = i(n);
			o(n, p)
		}
	}

	function o(t, e) {
		var a = t.href;
		if (!(a.indexOf("mogujie.com/mtalk/") > -1) && (l.test(a) || s.test(a))) {
			var o = t.getAttribute(m);
			o && u.test(o) || (o = n(t, e), t.setAttribute(m, o)), t.href = r(a, "ptp=" + o)
		}
	}

	function r(t, e) {
		var a = t.match(/(#.+)$/);
		return t = t.replace(/(#.+)$/, ""), t = t.replace(/ptp=[^&#]*/, ""), t += t.indexOf("?") > -1 ? "&" + e : "?" + e, t = t.replace(/[&]{2,}/g, "&").replace(/&$/, ""), t = t.replace(/\?&/g, "?"), a && (t += a[1]), t
	}

	function n(t, e) {
		var a, o = t.href.match(f),
			r = "AREA" === t.nodeName ? "area" : "a";
		o && (a = "_mt-" + o[2] + "-" + o[3]);
		var n, i = t.parentNode,
			p = "",
			c = [];
		if (!a) {
			for (; i && (c.push(i.nodeName), !(p = i.getAttribute("data-ptp"))) && "BODY" !== i.nodeName;) i = i.parentNode;
			if (!p) try {
				p = ptp.pageHash(c.join(""))
			} catch (d) {
				p = 0
			}
		}
		for (var m = i.getElementsByTagName(r), u = 0; u < m.length; u++) m[u].setAttribute("data-ptp-idx", u + 1);
		return n = t.getAttribute("data-ptp-idx"), e ? [v.a, v.b, e.c, e.d, v.e].join(".") : [v.a, v.b, a ? a : p, n, v.e].join(".")
	}

	function i(t) {
		if ($) {
			var t = $(t),
				e = t.closest("[data-ptp-customc]"),
				a = t.data("ptp-customc");
			if (a) return {
				c: a,
				d: $('[data-ptp-customc="' + a + '"]').index(t)
			};
			if (e && e.length > 0) return {
				c: e.data("data-ptp-customc"),
				d: $('[data-ptp-customc="' + e.data("data-ptp-customc") + '"]').index(e)
			}
		}
		return null
	}

	function p() {
		this.paramUrl = null, this.paramProto = {}, this.collectPtpCD = {
			isNeedPtp: "",
			_modelId: ""
		}, this.isNative = !1
	}
	var c = document,
		d = "tap" in c.createElement("div") ? "tap" : "mousedown",
		m = "data-ptp-cache-id",
		u = /ptp=[a-z0-9]+\.[a-z0-9]+\.[a-z0-9]+\.[a-z0-9]+\.[a-z0-9]+/i,
		l = /http[s]?:\/\/\w+\.mogujie\.com([\/]|\/.*|)$/,
		s = /mgj:\/\//,
		f = /\?.*[&]?mt=([^\.]+)\.([^\.]+)\.([^\.&#]+)/,
		g = document.getElementById("ptp-woodpecker-meta");
	if (g) {
		var v = {
			a: t(g, "site"),
			b: t(g, "page"),
			e: t(g, "req")
		};
		e(c, d, a), e(c, "touchstart", a), p.prototype = {
			init: function() {
				var t = this;
				return t.getParam(), t.paramUrl ? (t.getIsNative(), t.analyticalParam(), void t.boundDom()) : !1
			},
			getParam: function() {
				(window.log_stat_url || log_stat_url) && (this.paramUrl = window.log_stat_url || log_stat_url)
			},
			analyticalParam: function() {
				var t = this,
					e = t.paramUrl.match(/\w*=[\w.,%－\|\*]*/g),
					a = e.length - 1;
				if (e && e.length > 0)
					for (; a > 0; a--) {
						var o = e[a].match(/[\w%.,-]+/g);
						this.paramProto[o[0]] = o[1] || ""
					}
			},
			boundDom: function() {
				var t = this;
				e(document, d, function(e) {
					e = e || window.event;
					var a = e.target || e.srcElement;
					t.collectPtpCD.isNeedPtp = a.getAttribute("custom-ptp"), t.collectPtpCD._modelId = a.getAttribute("data-mid"), t.superStratum(a), t.collectPtpCD.isNeedPtp && t.replaceParam(t.collectPtpCD._modelId, t.getIndex(a))
				})
			},
			superStratum: function(t) {
				var e = this,
					a = t.parentNode;
				if (a && "#document" != a.nodeName && !e.collectPtpCD._modelId) {
					var o = a.getAttribute("custom-ptp"),
						r = a.getAttribute("data-mid");
					o && (e.collectPtpCD.isNeedPtp = o), r && (e.collectPtpCD._modelId = r), e.superStratum.call(e, a)
				}
			},
			getIndex: function(t) {
				for (var e = t.parentNode.children, a = 0, o = e.length; o > a; a++)
					if (e[a] == t) return a
			},
			replaceParam: function(t, e, a) {
				var o = this,
					r = o.paramProto.ptp_cnt,
					t = t || 0,
					n = a || "click",
					i = r.split(".");
				i[2] = "_modelId" + t, i[3] = e, (-1 == r.indexOf(i[1]) || -1 == o.paramProto.ptp_url.indexOf(i[1])) && (o.paramProto.ptp_ref = o.paramProto.ptp_url, o.paramProto.ptp_url = r), o.paramProto.rerefer = encodeURIComponent(window.location.href), o.paramProto.ptp_cnt = i.join("."), o.paramProto.custom_event = n, o.isNative ? (o.paramProto.ptp_info = encodeURIComponent("cnt=" + o.paramProto.ptp_cnt + "&url=" + o.paramProto.ptp_url + "&ref=" + o.paramProto.ptp_ref), o.sendAppLog()) : o.sendGet()
			},
			getIsNative: function() {
				var t = window.navigator.userAgent.toLocaleLowerCase();
				this.isNative = t.indexOf("mogujie") > -1 && -1 == t.indexOf("nonative")
			},
			sendGet: function() {
				var t = this,
					e = document.getElementById("log_img_data"),
					a = "",
					o = t.paramProto;
				for (key in o) a && (a += "&"), a = a + key + "=" + o[key];
				if (e) e.src = "http://log.juangua.com/mogu.js?" + a;
				else {
					var r = document.createElement("img");
					r.src = "http://log.juangua.com/mogu.js?" + a, r.id = "log_img_data", document.body.appendChild(r), r.style.display = "none"
				}
			},
			sendAppLog: function() {
				var t = this;
				_proto = t.paramProto, window.mgj && "object" == typeof window.mgj.tracker && "function" == typeof window.mgj.tracker.sendEvent && mgj.tracker.sendEvent("50001", _proto)
			},
			triggerLog: function(t, e, a) {
				this.replaceParam(t, e, a)
			}
		}, window.detePtp = new p, detePtp.init()
	}
}();